<template>
	<view>
		<view class="item" v-for="(item, index) in list" :key="item.id" @click="itemClick(index)">花费：{{ item.money }}</view>
		<view>总共：{{ total }}</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [{ id: 100, money: 100, checked: false }, { id: 101, money: 200, checked: false }]
		};
	},
	methods: {
		itemClick(index) {
			console.log(index,"111");
			this.list[index].checked = !this.list[index].checked;
		}
	},
	computed: {
		total: function() {
			// return 100
			var result = this.list.reduce((total, item) => {
				if (item.checked) {
					return total += item.money;
				}
				// return total;
			}, 0);
			// console.log(result)
			return result;
		}
	}
};
</script>

<style></style>
